﻿@{
    ViewBag.Title = "选择推送组系统";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script src="/Scripts/date.format.js" type="text/javascript"></script>
    <script type="text/javascript">
        var clickAll = true;
        var UrlArray = $.getUrlArray();
        var retArr = new Array();
        var ExpIDs = new Array();
        var selectCount = -1;
        var opts = {
            rows: 10,
            height: 450,
            url: "/ViewGroup/GetSelectGroupList",
            para: { dbName: encodeURI(UrlArray["dbName"]) },
            idField: "GroupID",
            checkbox: true,
            columns: [
                     { field: 'GroupName', title: '推送组名称', width: 25, sortable: true },
                    { field: 'Description', title: '描述', width: 35, sortable: true },
                    { field: 'TargetSysName', title: '对接系统', width: 25, sortable: true },
                    { field: 'CreateTime', title: '创建时间', width: 15, align: 'center', sortable: true }
                ],
            OnChickRow: function (value, rowData, rowIndex) {
                return clickRow(value, rowData, rowIndex, true);
            }
        };
        function clickRow(value, rowData, rowIndex, load) {
            var s = true;
            if (selectCount > -1 && ExpIDs.length >= selectCount) {
                alert("只可选择 " + selectCount + " 个，请检查选择项。");
                s = false;
                return false;
            }
            if (s) {
                $("#sel_content").append("<span class='s1 s1" + value + "'><a title='" + rowData.Description + "'>" + rowData.GroupName + "</a><span class='s2 s2" + value + "''>&nbsp;X&nbsp;</span></span>");

                $(".s2" + value).bind("click", function () {
                    $(".s1" + value).remove();
                    $(".s2" + value).remove();
                    for (var j = 0; j < retArr.length; j++) {
                        if (retArr[j].GroupID == value) {
                            retArr.removeAt(j);
                        }
                    }
                    ExpIDs.removeValue(value);
                    opts.para["ExpIDs"] = ExpIDs.join(",");
                    initTable("DataGrid2", opts);
                });
                retArr.push(rowData);
                ExpIDs.push(value);
                if (load) {
                    opts.para["ExpIDs"] = ExpIDs.join(",");
                    initTable("DataGrid2", opts);
                }
                return true;
            }
        }
        $(function () {
            selectCount = UrlArray["selectCount"];
            if (typeof selectCount === "undefined" || selectCount == null)
                selectCount = -1;
            page_Init();
            InitList();
        });
        function page_Init() {
            $("body").css("overflow", "hidden");
        }
        function DoAction(i, v) {
            var arr = new Array();
            arr.push(i);
            arr.push(v);
            returnParent(arr);
        }
        function InitList() {
            opts.para["groupName"] = $.trim($("#txt_GroupName").val());
            opts.para["SysName"] = $.trim($("#txt_SysName").val());
            $("#DataGrid2").dg(opts);
        }
        function btnSearch() {
            thisPageNum = 1;
            InitList();
        }
        function flexiSelect() {
            if (retArr.length < 1) {
                alert('请选择一条数据!');
                return false;
            }
            if (selectCount > -1 && retArr.length > selectCount) {
                alert("只可选择 " + selectCount + " 个，请检查选择项。");
                return false;
            }
            returnParent(retArr);
            return false;
        }
    </script>
}
<div style="height: 470px; padding-left: 5px; padding-right: 5px; overflow: hidden;
    overflow-y: auto;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                推送组搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                推送组名：
                <input type="text" id="txt_GroupName" style="width: 200px;" />
                对接系统：
                <input type="text" id="txt_SysName" style="width: 200px;" />
                <input type="button" value="搜索" class="button" onclick="btnSearch()" />
            </td>
        </tr>
    </table>
    <table id="selected" style="width: 100%;">
        <tr>
            <td width="50">
                已选择：
            </td>
            <td>
                <div id="sel_content">
                </div>
            </td>
            <td width="50">
                <input type="button" value=" 确定 " class="button" onclick="flexiSelect()" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                推送组列表<span id="type_Name"></span>
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table id="DataGrid2" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
